//
//  Person.m
//  02-ClassAndObject
//
//  Created by dllo on 16/7/5.
//  Copyright © 2016年 daming. All rights reserved.
//

#import "Person.h"

@implementation Person
// 方法的实现: 方法加{}
- (void)sleep:(NSInteger)time {
//     NSLog属于C语言的函数
    NSLog(@"睡了%ld年", time);
}
//set方法的实现
- (void)setName:(NSString *)name {
    
    if (_name != name) {
        [_name release];
        _name = [name retain];
    }
}
- (NSString *)className {
    return [[_name retain]autorelease];
}
// 命名规范
// 实现大括号前,要加空格和回车
// 无论调用哪个初始化方法, 都会执行的初始化方法,称为指派初始化
- (instancetype)initWithName:(NSString *)name
                         age:(NSInteger)age {
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
    }
    return self;
}
+ (instancetype)personWithName:(NSString *)name
                           age:(NSInteger)age{
    return [[[Person alloc] initWithName:name age:age]autorelease];
}

@end
